package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DAO.LogDAO;

/**
 * Servlet implementation class deleteLogServlet
 */
public class deleteLogServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public deleteLogServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();
		
		String operaterID = request.getParameter("operaterID");		
		Vector operaterIDVector = new Vector();
        
		int start = 0 , next = 0 , end;
		end = operaterID.lastIndexOf(",");

		while(next != end)
		{
			next = operaterID.indexOf(",", start + 1);
			String str = operaterID.substring(start + 1, next);
			start = next;
			operaterIDVector.addElement(str);
		}
		
		if(operaterIDVector.size()==0)
		{
			out.println("{success:true,msg:'No record have been choosed'}");
		}
		else{
			LogDAO delLogDAO = new LogDAO();
			delLogDAO.deleteLog(operaterIDVector);
		
			out.println("{success:true,msg:'succeed'}");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
